/**
 *    Copyright (C) 2009  Victor Smirnov <aist11@gmail.com>
 *
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License along
 *    with this program; if not, write to the Free Software Foundation, Inc.,
 *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *    See LICENSE.exceptions in the root folder of this project for possible
 *    exceptions
 *
 */

#ifndef _CUBEFS_API_TOOLS_VERSION_HPP
#define	_CUBEFS_API_TOOLS_VERSION_HPP

#include <cubefs/api/types.hpp>
#include <cubefs/api/macro.hpp>
#include <cubefs/api/reflection/type_name.hpp>
#include <cubefs/api/reflection/type_hash.hpp>
#include <cubefs/api/reflection/value.hpp>
#include <iostream>

namespace cubefs { namespace api {

class CUBEFS_API Version {
	Int magor_;
	Int minor_;
	Int patchset_;
	BigInt timestamp_;
public:
	Version(Int magor = 0, Int minor = 0, Int patchset = 0, BigInt timestamp = 0):
		magor_(magor), minor_(minor), patchset_(patchset),
		timestamp_(timestamp) {}

	Version(StringRef str);

	Int GetMagor() const {
		return magor_;
	}

	Int GetMinor() const {
		return minor_;
	}

	Int GetPatchset() const {
		return patchset_;
	}

	BigInt GetTimestamp() const {
		return timestamp_;
	}

	String str() const;

	bool IsCompatible(const Version& other) const {
		return GetMagor() == other.GetMagor() && GetMinor() <= other.GetMinor();
	}

	bool operator == (const Version& other) const;
	bool operator >= (const Version& other) const;

	bool IsMatches(const Version& other) const;
};

CUBEFS_DECLARE_TYPENAME(Version, "cubefs::api::Version");
CUBEFS_DEFINE_TYPE_HASH(Version, 100);

typedef TypedValue<Version>								VersionValue;

}}


namespace std {
CUBEFS_API ostream& operator<<(ostream& os, const cubefs::api::Version& v);
}

#endif
